<template>
  <div class="home">
    <h2>路由跳转传参-params传参</h2>
    <ul>
      <li v-for="list in lists" :key="list.id" @click="toHomeDetail(list.title)">{{ list.title }}</li>
    </ul>
  </div>
</template>

<script setup>
import { ref } from 'vue';
// 使用useRouter来获取vue-Router的实例
import { useRouter } from 'vue-router';
// 执行函数得到router对象
let router = useRouter();
console.log(router);

let lists = ref([
  {
    id: 1,
    title: '标题1'
  },
  {
    id: 2,
    title: '标题2'
  }, {
    id: 3,
    title: '标题3'
  }
])

let toHomeDetail = (title) => {
  router.push({
    name: 'homedetail',
    params: {
      title
    }
  });
}
</script>
